package com.ccys.cms.controller.userManagement;

import com.ccys.cms.service.userManagement.TblLabResultWebService;
import com.ccys.common.constants.ContextConstants;
import com.ccys.common.constants.TouristApi;
import com.ccys.common.util.Kit;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.userManagement.TblLabResultDTO;
import com.ccys.db.entity.TblLabResult;
import com.ccys.db.entity.TblSupplier;
import com.ccys.db.mapper.TblSupplierMapper;
import com.ccys.db.vo.userManagement.SelectSupplierWebVO;
import com.ccys.db.vo.userManagement.TblLabResultWebVO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "用户管理-Laboratory results与Health screening 中的Laboratory results和Third party health screening 通用")
@RequestMapping("userManagement")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE, RequestMethod.PUT}) // 开启跨域访问允许
@SuppressWarnings("unchecked")
public class LabResultWebController {

    @Autowired
    private TblLabResultWebService tblLabResultWebService;



    @GetMapping("labResult")
    @ApiOperation("获取列表（三方 Third party health screening 列表 也用此接口类型区分）")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "status", value = "三方上传时的状态值,Error;Unverified;Verified,其中Error和 Unverified 在 cms 可以被修改成Verified", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "types", value = "类型多个英文逗号分割（0:三方上传 ;1:手动上传;2:医生端上传）", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "memId", value = "Patient（memId）", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "refNumber", value = "Reference no.", required = false, dataType = "string", paramType = "query"),

        @ApiImplicitParam(name = "id", value = "对象id", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "startTime", value = "开始时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "endTime", value = "结束时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "orderByStr", value = "排序字段（后端返回的字段  asc升序，desc 降序,加上end后缀。示例（createdOn降序排 则传值 createdOn descend））",paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = TblLabResultWebVO.class)
    })
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, @ApiIgnore TblLabResultDTO dto) {
        return this.tblLabResultWebService.listObjectsCms(request, response, dto);
    }
    @GetMapping("labResult/supplierList")
    @ApiOperation("查询可选择的供应商")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "type", value = "默认查询类型为service的数据   ", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = SelectSupplierWebVO.class)
    })
    public ResponseResult listSelectSupplier( @ApiIgnore TblSupplier dto) {
        return this.tblLabResultWebService.listSelectSupplier(dto);
    }

    @PostMapping("labResult")
    @ApiOperation("添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "0:三方上传 ;1:手动上传;2:医生端上传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "memId", value = "memId", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "resultPdf", value = "resultPdf", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "autoLabResultPdf", value = "全路径", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "resultUploadedOn", value = "resultUploadedOn", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "Laboratory test name", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "refNumber", value = "Laboratory reference number", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "supplierId", value = "Supplier", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "screeningTime", value = " Screening time", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "reportTime", value = "Report time", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "bloodPressureTopValue", value = "BP 最大值", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "bloodPressureBottomValue", value = "BP 最小值", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "heartRate", value = "HR", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "weight", value = "weight", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "height", value = "height", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "bookingId", value = "三方上传没有，医生端上传时关联问诊", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "profileId", value = "存储的是plan_benefit_id", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "三方上传时的状态值,Error;Unverified;Verified,其中Error和 Unverified 在 cms 可以被修改成Verified", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult save(@ApiIgnore TblLabResult entity) {
        entity.setId(null);
        return this.tblLabResultWebService.change(entity);
    }


    @PutMapping("labResult")
    @ApiOperation("编辑")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "ID号", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "type", value = "0:三方上传 ;1:手动上传;2:医生端上传", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "memId", value = "memId", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "resultPdf", value = "resultPdf", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "autoLabResultPdf", value = "全路径", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "resultUploadedOn", value = "resultUploadedOn(yyyy-MM-dd HH:mm:ss)", required = false, dataType = "date", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "name", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "refNumber", value = "refNumber", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "supplierId", value = "supplierId", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "screeningTime", value = "screeningTime(yyyy-MM-dd HH:mm:ss)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "reportTime", value = "reportTime(yyyy-MM-dd HH:mm:ss)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "bloodPressureTopValue", value = "bloodPressureTopValue", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "bloodPressureBottomValue", value = "bloodPressureBottomValue", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "heartRate", value = "heartRate", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "weight", value = "weight", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "height", value = "height", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "bookingId", value = "三方上传没有，医生端上传时关联问诊", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "profileId", value = "存储的是plan_benefit_id", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "status", value = "三方上传时的状态值,Error;Unverified;Verified,其中Error和 Unverified 在 cms 可以被修改成Verified", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult edit(@ApiIgnore TblLabResult entity) {
        Kit.allParamValid(entity, "id");
        return this.tblLabResultWebService.change(entity);
    }


    @DeleteMapping("labResult")
    @ApiOperation("删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "ID号", required = true, dataType = "string", paramType = "query")
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult delete(@ApiIgnore TblLabResult dto) {
        Kit.allParamValid(dto, "id");
        return this.tblLabResultWebService.delete(dto);
    }




    //公用以下两种数据源一样公用导出模版
    //   Home  /   Health screening / Laboratory results   导出文件模版
    //   Home  /   Health screening / Third party health screening 导出文件模版
    @TouristApi
    @GetMapping("labResult/export")
    @ApiOperation("导出列表数据")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "status", value = "三方上传时的状态值,Error;Unverified;Verified,其中Error和 Unverified 在 cms 可以被修改成Verified", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "types", value = "类型多个英文逗号分割（0:三方上传 ;1:手动上传;2:医生端上传）", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "memId", value = "Patient（memId）", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "refNumber", value = "Reference no.", required = false, dataType = "string", paramType = "query"),

        @ApiImplicitParam(name = "id", value = "对象id", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "startTime", value = "开始时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "endTime", value = "结束时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "orderByStr", value = "排序字段（后端返回的字段  asc升序，desc 降序,加上end后缀。示例（createdOn降序排 则传值 createdOn descend））",paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = TblLabResultWebVO.class)
    })
    public ResponseResult exportLabResult(HttpServletRequest request, HttpServletResponse response, @ApiIgnore TblLabResultDTO dto) {
        return this.tblLabResultWebService.exportLabResult(request, response, dto);
    }




}